package com.xp.code.daoImpl;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import oracle.jdbc.oracore.OracleType;

import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.xp.code.dao.IAuthsDao;
import com.xp.code.dao.IExampleDao;
import com.xp.code.jpa.DefaultJPADAO;
import com.xp.code.vo.MenuVO;

/**
 * 
 * @author HAHA
 *
 */
@Repository("authsDao")
public class AuthsDao extends DefaultJPADAO implements IAuthsDao {

	private Logger loger=Logger.getLogger(AuthsDao.class);
	
	/* (non-Javadoc)
	 * @see com.xp.code.daoImpl.IAuthsDao#getAuthSInfo(java.lang.String)
	 */
	@SuppressWarnings("unchecked")
	public List<MenuVO> getAuthSInfo(String userid)throws Exception{
		CallableStatement cs=null;
		ResultSet rs=null;
		MenuVO menuEntity=null;
		List<MenuVO> list=null;
		try{
		Session session=(Session)this.getEntityManager().getDelegate();
		Connection conn=session.connection();
		cs=conn.prepareCall("{CALL PACKAGEXPSYS_MENU.GetMenuByUserID(?,?)}");
		cs.setString(1, userid);
		cs.registerOutParameter(2, oracle.jdbc.driver.OracleTypes.CURSOR);
		cs.executeQuery();
		rs=(ResultSet)cs.getObject(2);
		list=new ArrayList<MenuVO>();
		while(rs.next()){
			menuEntity=new MenuVO();
			menuEntity.setVarcode(rs.getString("VARCODE"));
			menuEntity.setParentCode(rs.getString("PARENTCODE"));
			menuEntity.setVarname(rs.getString("VARNAME"));
			menuEntity.setVarlevel(rs.getString("ISLEVEL"));
			menuEntity.setVarurl(rs.getString("VARURL"));
			menuEntity.setVarseq(rs.getString("SEQUENCE"));
			list.add(menuEntity);
		}
		}finally{
			if (rs != null)
			{
				rs.close();
			}
			if (cs != null)
			{
				cs.close();
			}
		}
		return list;
	}
}
